package view;

/*
Cours :             LOG120 
Session :           Saison (hiver) 
Groupe :            01 
Projet :            Laboratoire #2
Etudiant(e)(s) :    Jeremy Moreau
                    Alexandre Richard
                    Philippe Pigeon
Code(s) perm. :     MORJ91010106
					RICA10028806 
                    PIGP08058903
Professeur :        Ghizlane El Boussaidi  
Date remise :       2012-03-010  
*/

import java.awt.Color;
import java.util.ArrayList;
import java.util.Observable;
import javax.swing.JList;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import controller.CommandeController;
import model.Plat;
import model.Restaurant;

@SuppressWarnings("serial")
public class RestaurantView extends AbstractView implements ListSelectionListener
{
	JList lvRestaurants;
	ArrayList<Restaurant> restaurants;
	
	public RestaurantView(CommandeController _ctrl, ArrayList<Restaurant> _restaurants)
	{
		super(_ctrl);
		restaurants = _restaurants;
		init();
	}
	
	public void init()
	{
		setLayout(null);
		setBounds(10, 10, 120, 220);
		
		lvRestaurants = new JList(restaurants.toArray());
		lvRestaurants.addListSelectionListener(this);
		lvRestaurants.setBounds(0, 0, 120, 220);
		lvRestaurants.setBorder(new LineBorder(Color.BLACK));
		
		add(lvRestaurants);
		setVisible(true);
	}	
	
	public Restaurant getSelectedRestaurant()
	{
		return (Restaurant)lvRestaurants.getSelectedValue();
	}
	
	public void load(ArrayList<Restaurant> _restaurants)
	{
		restaurants = _restaurants;	
	}

	@Override
	public void valueChanged(ListSelectionEvent e) 
	{
		getCCtrl().updateSelectedResto( restaurants.get(lvRestaurants.getSelectedIndex()) );
	}

	@Override
	public void update(Observable o, Object arg) {}


}
